#ifndef __CONDITION_POSIX_H__
#define _CONDITION_POSIX_H__

#include "mutex.h"

namespace dsth {
    
class Condition {
public:
    explicit Condition(Mutex& mutex) : mutex_(mutex) {
        pthread_cond_init(&pcond_, NULL);
    }

    ~Condition() {
        pthread_cond_destroy(&pcond_);
    }

    void Wait() {
        pthread_cond_wait(&pcond_, mutex_.GetInnerMutex());
    }

    void Notify() {
        pthread_cond_signal(&pcond_);
    }

    void NotifyAll() {
        pthread_cond_broadcast(&pcond_);
    }
    
private:
    // Can't invoke copy constructor or assignment operator
    Condition(const Condition&);
    void operator=(const Condition&);

    Mutex& mutex_;
    pthread_cond_t pcond_;
};

} // namespace
#endif // _CONDITION_POSIX_H__
